package zhtt;

import net.sf.ehcache.hibernate.HibernateUtil;
import org.junit.Test;

import java.util.Set;

/**
 * Created by zhtt on 2017/4/12.
 */
public class JunitTest02 extends JunitTestUtil {

    @Test
    /**
     * 一条sql语句完成查询
     * fetch=join:以左外连接的方式查询出全部数据
     *
     * 当打印Country时，才会查询Country
     */
    public void join(){
        try{
            zhtt.demo05_join_singleendedload.Minister minister=session.get(zhtt.demo05_join_singleendedload.Minister.class,6);
            System.out.println("这是查询之后");
            zhtt.demo05_join_singleendedload.Country country=minister.getCountry();
            System.out.println("这是从minister中get之后");
            System.out.println(minister);
            System.out.println("这是打印Minister之后");
            System.out.println(country);
            System.out.println("这是打印country之后");
        }catch (Exception e){e.printStackTrace();}
    }

    @Test
    /**
     *  1、查询minister；
     *      getCountry()后未查询country，当打印country时才查询country
     *  2、查询country
     *  3、查询country、minister（原因是country中有个toString()方法，此方法中有minister）
     *  三条sql语句全部加载完成
     */
    public void select(){
        try{
            zhtt.demo06_select_singleendedload.Minister minister=session.get(zhtt.demo06_select_singleendedload.Minister.class,6);
            System.out.println("这是查询之后");
            zhtt.demo06_select_singleendedload.Country country=minister.getCountry();
            System.out.println("这是从minister中get之后");
            System.out.println(minister);
            System.out.println("这是打印Minister之后");
            System.out.println(country);
            System.out.println("这是打印country之后");
        }catch (Exception e){e.printStackTrace();}
    }

    @Test
    /**
     *  1、查询minister；
     *  2、查询country
     *  3、查询country、minister（原因是country中有个toString()方法，此方法中有minister）
     *  三条sql语句全部加载完成
     */
    public void select_false(){
        try{
            zhtt.demo07_select_false_singleendedload.Minister minister=session.get(zhtt.demo07_select_false_singleendedload.Minister.class,6);
            System.out.println("这是查询之后");
            zhtt.demo07_select_false_singleendedload.Country country=minister.getCountry();
            System.out.println("这是从minister中get之后");
            System.out.println(minister);
            System.out.println("这是打印Minister之后");
            System.out.println(country);
            System.out.println("这是打印country之后");
        }catch (Exception e){e.printStackTrace();}
    }

    @Test
    /**
     *  proxy:首次查询只查minister(多方，未查询一方)
     *  2、从minister中getCountry()后未执行查询country的方法
     *  3、当使用country.get时，发出查询country的语句
     *  4、通过country使用minister时，发出查询minister的语句
     */
    public void select_proxy(){
        try{
            zhtt.demo08_select_proxy_singleendedload.Minister minister=session.get(zhtt.demo08_select_proxy_singleendedload.Minister.class,6);
            System.out.println("这是查询之后");
            zhtt.demo08_select_proxy_singleendedload.Country country=minister.getCountry();
            System.out.println("这是从minister中get之后");
            System.out.println(minister);
            System.out.println("这是打印Minister之后");
            System.out.println(country);
            System.out.println("这是打印country之后");
        }catch (Exception e){e.printStackTrace();}
    }

    @Test
    /**
     *  proxy:首次查询只查minister(多方，未查询一方)
     *  2、从minister中getCountry()后未执行查询country的方法
     *  3、当使用country.get时，发出查询country的语句
     *  4、通过country使用minister时，发出查询minister的语句
     */
    public void select_proxy_true(){
        try{
            zhtt.demo09_select_proxy_true_singleendedload.Minister minister=session.get(zhtt.demo09_select_proxy_true_singleendedload.Minister.class,6);
            System.out.println("这是查询之后");
            zhtt.demo09_select_proxy_true_singleendedload.Country country=minister.getCountry();
            System.out.println("这是从minister中get之后");
            System.out.println(minister);
            System.out.println("这是打印Minister之后");
            System.out.println(country);
            System.out.println("这是打印country之后");
        }catch (Exception e){e.printStackTrace();}
    }
}
